package com.pactera.madp.cp.controller.oms.job;

import com.pactera.madp.common.log.annotation.SysLog;
import com.pactera.madp.common.security.annotation.Inner;
import com.pactera.madp.cp.api.entity.CorpEntity;
import com.pactera.madp.cp.service.ICorpService;
import com.pactera.madp.cp.service.IWorkMsgConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * SensitiveWordsMonitorController
 *
 * @author jun
 * @version 1.0
 * 2021/8/18 14:59
 **/
@RestController
@RequestMapping("/sensitive-words-monitor")
@Api(value = "sensitive-words-monitor",tags = "敏感词监控任务")
public class SensitiveWordsMonitorWorkController {

    @Autowired
    private ICorpService corpServiceImpl;
    @Autowired
    private IWorkMsgConfigService msgConfigService;

    @SysLog("敏感词监控信息同步")
    @Inner
    @PostMapping("/work")
    @ApiOperation(value = "敏感词监控信息同步")
    public void autoSensitiveWords(){
        //查出所有会话消息
        String clStr = "id";
        List<CorpEntity> corpEntityList = corpServiceImpl.getCorpIds(clStr);
        StringBuilder sb = new StringBuilder();
        for (CorpEntity corpEntity:
                corpEntityList) {
            sb.append(corpEntity.getCorpId());
            sb.append(",");
        }
        String corpIds = sb.substring(0,sb.length()-1);
        autoSensitive(corpIds);
    }

    /**
     * 敏感词接口信息同步异步中转
     * @param corpIds
     */
    @Async
    void autoSensitive(String corpIds){
        msgConfigService.getWorkMsgByCorpId(corpIds,"corp_id,msg_id");
    }

}
